﻿using System;
using System.Data;
using DataAccess;

[assembly: CLSCompliant(true)]
namespace Business
{
    public class UserBll
    {
        private UserDao _userDao;
        /// <summary>
        /// Initializes a new instance of the <see cref="UserBll"/> class.
        /// </summary>
        public UserBll()
        {
            _userDao = new UserDao();
        }
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public bool AuthenticateUser(string userName, string password)
        {
            try
            {
                int result = _userDao.Authenticate(userName, password);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Adds the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="fullname">The fullname.</param>
        /// <param name="email">The email.</param>
        /// <param name="phone">The phone.</param>
        /// <param name="address">The address.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        public bool AddUser(string userName, string password, string fullName, string email, string phone,
            string address, int status)
        {
            try
            {
                int result = _userDao.AddUser(userName, password, fullName, email, phone, address, status);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="username">The username.</param>
        /// <param name="fullname">The fullname.</param>
        /// <param name="email">The email.</param>
        /// <param name="phone">The phone.</param>
        /// <param name="address">The address.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        public bool UpdateUser(int userId, string userName, string fullName, string email, 
            string phone, string address, int status)
        {
            try
            {
                int result = _userDao.UpdateUser(userId, userName, fullName, email, phone, address, status);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Views all users.
        /// </summary>
        /// <returns></returns>
        public DataTable ViewAllUsers()
        {
            try
            {
                return _userDao.ViewAllUser();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Views the user by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public DataTable ViewUserById(int id)
        {
            try
            {
                return _userDao.ViewUserById(id);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Deactives the user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool DeactivateUser(int userId)
        {
            try
            {
                int result = _userDao.DeactivateUser(userId);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
